import "babel-regenerator-runtime";
import "core-js/fn/promise";
import "core-js/fn/object/assign";

import {AJAX} from 'methods/query.js';
import Vue from "vue";
import VueRouter from "vue-router";
import VueResource from "vue-resource-2";
import router_map from "services/router";

import "styles/base.less";
import "styles/reset.less";
import "utilities/vue-mixin";
import "weui/dist/style/weui.css";

Vue.use(VueRouter);
Vue.use(VueResource);
const router = new VueRouter();
router.map(router_map);
router.beforeEach(async transition => {
  let app = router.app;
  app.openId = app.$route.query.openId || sessionStorage.getItem("openId");
  if (app.$route.path.indexOf('pay-details') === -1 && !app.openId) {
    app.openId = await AJAX.openId(app.code);
    sessionStorage.setItem("openId", app.openId);
  }
  return true;
});
router.start({
  data() {
    return {
      openId: "",
      code: this.$route.query.code,
      domain: "http://sxdz.test.ebjcloud.com/"
    };
  },
  async ready() {
    // console.log(this.openId);
  }
}, document.documentElement);
